<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>xmake v2.5.9 发布，改进 C++20 模块，并支持 Nim, Keil MDK 和 Unity Build</title>
    <meta name="description" content="xmake 是一个基于 Lua 的轻量级跨平台构建工具，使用 xmake.lua 维护项目构建，相比 makefile/CMakeLists.txt，配置语法更加简洁直观，对新手非常友好，短时间内就能快速入门，能够让用户把更多的精力集中在实际的项目开发上。这个版本，我们增加了大量重量级的新特性，例如：Nim 语言...">

    
    <meta name="keywords" content="xmake,lua,C/C++,Nim,Keil,MDK,circle,Unity,Build,C++20,Modules,lua5.4,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/cn/2021/10/30/xmake-update-v2.5.9/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />

    <!-- css -->
    <link href="/css/reward.css" rel="stylesheet" type="text/css"> 




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/cn" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/?lang=0">
                    
                        <i class="fa fa-home"></i>English
                    </a>
                </li>

                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>项目
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/archive/">
                            
                        
                            <i class="fa fa-archive"></i>归档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/category/">
                            
                        
                            <i class="fa fa-th-list"></i>分类
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/tag/">
                            
                        
                            <i class="fa fa-tags"></i>标记
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/docs/">
                            
                        
                            <i class="fa fa-book"></i>文档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="https://xmake.io/#/zh-cn/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>社区
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/donation/">
                            
                        
                            <i class="fa fa-heart"></i>捐助
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/about/">
                            
                        
                            <i class="fa fa-user"></i>关于
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>xmake v2.5.9 发布，改进 C++20 模块，并支持 Nim, Keil MDK 和 Unity Build</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2021-10-30
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#xmake" title="Category: xmake" rel="category">xmake</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a-->
        <a href="/cn/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a>&nbsp;
    
        <!--a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a-->
        <a href="/cn/tag/#lua" title="Tag: lua" rel="tag">lua</a>&nbsp;
    
        <!--a href="/tag/#C%2FC%2B%2B" title="Tag: C/C++" rel="tag">C/C++</a-->
        <a href="/cn/tag/#C/C++" title="Tag: C/C++" rel="tag">C/C++</a>&nbsp;
    
        <!--a href="/tag/#Nim" title="Tag: Nim" rel="tag">Nim</a-->
        <a href="/cn/tag/#Nim" title="Tag: Nim" rel="tag">Nim</a>&nbsp;
    
        <!--a href="/tag/#Keil" title="Tag: Keil" rel="tag">Keil</a-->
        <a href="/cn/tag/#Keil" title="Tag: Keil" rel="tag">Keil</a>&nbsp;
    
        <!--a href="/tag/#MDK" title="Tag: MDK" rel="tag">MDK</a-->
        <a href="/cn/tag/#MDK" title="Tag: MDK" rel="tag">MDK</a>&nbsp;
    
        <!--a href="/tag/#circle" title="Tag: circle" rel="tag">circle</a-->
        <a href="/cn/tag/#circle" title="Tag: circle" rel="tag">circle</a>&nbsp;
    
        <!--a href="/tag/#Unity" title="Tag: Unity" rel="tag">Unity</a-->
        <a href="/cn/tag/#Unity" title="Tag: Unity" rel="tag">Unity</a>&nbsp;
    
        <!--a href="/tag/#Build" title="Tag: Build" rel="tag">Build</a-->
        <a href="/cn/tag/#Build" title="Tag: Build" rel="tag">Build</a>&nbsp;
    
        <!--a href="/tag/#C%2B%2B20" title="Tag: C++20" rel="tag">C++20</a-->
        <a href="/cn/tag/#C++20" title="Tag: C++20" rel="tag">C++20</a>&nbsp;
    
        <!--a href="/tag/#Modules" title="Tag: Modules" rel="tag">Modules</a-->
        <a href="/cn/tag/#Modules" title="Tag: Modules" rel="tag">Modules</a>&nbsp;
    
        <!--a href="/tag/#lua5.4" title="Tag: lua5.4" rel="tag">lua5.4</a-->
        <a href="/cn/tag/#lua5.4" title="Tag: lua5.4" rel="tag">lua5.4</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <p><a href="https://github.com/xmake-io/xmake">xmake</a> 是一个基于 Lua 的轻量级跨平台构建工具，使用 xmake.lua 维护项目构建，相比 makefile/CMakeLists.txt，配置语法更加简洁直观，对新手非常友好，短时间内就能快速入门，能够让用户把更多的精力集中在实际的项目开发上。</p>

<p>这个版本，我们增加了大量重量级的新特性，例如：Nim 语言项目的构建支持，Keil MDK，Circle 和 Wasi 工具链支持。</p>

<p>另外，我们对 C++20 Modules 进行了大改进，不仅支持最新 gcc-11, clang 和 msvc 编译器，而且还得模块间依赖做了自动分析，实现最大程度的并行化编译支持。</p>

<p>最后，还有一个比较有用的特性就是 Unity Build 支持，通过它我们可以对 C++ 代码的编译速度做到很大程度的提升。</p>

<ul>
  <li><a href="https://github.com/xmake-io/xmake">项目源码</a></li>
  <li><a href="https://xmake.io/#/zh-cn/">官方文档</a></li>
  <li><a href="https://xmake.io/#/zh-cn/about/course">入门课程</a></li>
</ul>

<h2 id="新特性介绍">新特性介绍</h2>

<h3 id="nimlang-项目构建">Nimlang 项目构建</h3>

<p>最近，我们新增了对 Nimlang 项目的构建支持，相关 issues 见：<a href="https://github.com/xmake-io/xmake/issues/1756">#1756</a></p>

<h4 id="创建空工程">创建空工程</h4>

<p>我们可以使用 <code class="highlighter-rouge">xmake create</code> 命令创建空工程。</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code>xmake create -l nim -t console test
xmake create -l nim -t static test
xmake create -l nim -t shared test
</code></pre>
</div>

<h4 id="控制台程序">控制台程序</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/main.nim"</span><span class="p">)</span>
</code></pre>
</div>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> -v
</span>[ 33%]: linking.release test
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/test/macosx/x86_64/release/nimcache -o:b
uild/macosx/x86_64/release/test src/main.nim
[100%]: build ok!
</code></pre>
</div>

<h4 id="静态库程序">静态库程序</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"static"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/foo.nim"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_deps</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/main.nim"</span><span class="p">)</span>
</code></pre>
</div>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> -v
</span>[ 33%]: linking.release libfoo.a
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/foo/macosx/x86_64/release/nimcache --app
:staticlib --noMain --passC:-DNimMain=NimMain_B6D5BD02 --passC:-DNimMainInner=NimMainInner_B6D5B
D02 --passC:-DNimMainModule=NimMainModule_B6D5BD02 --passC:-DPreMain=PreMain_B6D5BD02 --passC:-D
PreMainInner=PreMainInner_B6D5BD02 -o:build/macosx/x86_64/release/libfoo.a src/foo.nim
[ 66%]: linking.release test
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/test/macosx/x86_64/release/nimcache --pa
ssL:-Lbuild/macosx/x86_64/release --passL:-lfoo -o:build/macosx/x86_64/release/test src/main.nim
[100%]: build ok!
</code></pre>
</div>

<h4 id="动态库程序">动态库程序</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/foo.nim"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_deps</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/main.nim"</span><span class="p">)</span>
</code></pre>
</div>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> -rv
</span>[ 33%]: linking.release libfoo.dylib
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/foo/macosx/x86_64/release/nimcache --app
:lib --noMain -o:build/macosx/x86_64/release/libfoo.dylib src/foo.nim
[ 66%]: linking.release test
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/test/macosx/x86_64/release/nimcache --pa
ssL:-Lbuild/macosx/x86_64/release --passL:-lfoo -o:build/macosx/x86_64/release/test src/main.nim
[100%]: build ok!
</code></pre>
</div>

<h4 id="c-代码混合编译">C 代码混合编译</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"static"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_deps</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/main.nim"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="nimble-依赖包集成">Nimble 依赖包集成</h4>

<p>完整例子见：<a href="https://github.com/xmake-io/xmake/tree/dev/tests/projects/nim/nimble_package">Nimble Package Example</a></p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">add_requires</span><span class="p">(</span><span class="s2">"nimble::zip &gt;0.3"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/main.nim"</span><span class="p">)</span>
    <span class="n">add_packages</span><span class="p">(</span><span class="s2">"nimble::zip"</span><span class="p">)</span>
</code></pre>
</div>

<p>main.nim</p>

<div class="language-nim highlighter-rouge"><pre class="highlight"><code><span class="k">import</span> <span class="n">zip</span><span class="o">/</span><span class="n">zlib</span>

<span class="n">echo</span> <span class="n">zlibVersion</span><span class="p">()</span>
</code></pre>
</div>

<h4 id="native-依赖包集成">Native 依赖包集成</h4>

<p>完整例子见：<a href="https://github.com/xmake-io/xmake/tree/dev/tests/projects/nim/native_package">Native Package Example</a></p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">add_requires</span><span class="p">(</span><span class="s2">"zlib"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/main.nim"</span><span class="p">)</span>
    <span class="n">add_packages</span><span class="p">(</span><span class="s2">"zlib"</span><span class="p">)</span>
</code></pre>
</div>

<p>main.nim</p>

<div class="language-nim highlighter-rouge"><pre class="highlight"><code><span class="k">proc </span><span class="nf">zlibVersion</span><span class="p">():</span> <span class="n">cstring</span> <span class="p">{.</span><span class="n">cdecl</span><span class="p">,</span> <span class="n">importc</span><span class="p">}</span>

<span class="n">echo</span> <span class="n">zlibVersion</span><span class="p">()</span>
</code></pre>
</div>

<h3 id="unity-build-加速">Unity Build 加速</h3>

<p>我们知道，C++ 代码编译速度通常很慢，因为每个代码文件都需要解析引入的头文件。</p>

<p>而通过 Unity Build，我们通过将多个 cpp 文件组合成一个来加速项目的编译，其主要好处是减少了解析和编译包含在多个源文件中的头文件内容的重复工作，头文件的内容通常占预处理后源文件中的大部分代码。</p>

<p>Unity 构建还通过减少编译链创建和处理的目标文件的数量来减轻由于拥有大量小源文件而导致的开销，并允许跨形成统一构建任务的文件进行过程间分析和优化（类似于效果链接时优化）。</p>

<p>它可以极大提升 C/C++ 代码的编译速度，通常会有 30% 的速度提升，不过根据项目的复杂程度不同，其带来的效益还是要根据自身项目情况而定。</p>

<p>xmake 在 v2.5.9 版本中，也已经支持了这种构建模式。相关 issues 见 <a href="https://github.com/xmake-io/xmake/issues/1019">#1019</a>。</p>

<h4 id="如何启用">如何启用？</h4>

<p>我们提供了两个内置规则，分别处理对 C 和 C++ 代码的 Unity Build。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"c.unity_build"</span><span class="p">)</span>
<span class="n">add_rules</span><span class="p">(</span><span class="s2">"c++.unity_build"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="batch-模式">Batch 模式</h4>

<p>默认情况下，只要设置上述规则，就会启用 Batch 模式的 Unity Build，也就是 xmake 自动根据项目代码文件，自动组织合并。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"src"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"c++.unity_build"</span><span class="p">,</span> <span class="p">{</span><span class="n">batchsize</span> <span class="o">=</span> <span class="mi">2</span><span class="p">})</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"src/*.cpp"</span><span class="p">)</span>
</code></pre>
</div>

<p>我们可以额外通过设置 <code class="highlighter-rouge"><span class="p">{</span><span class="err">batchsize</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="err">2</span><span class="p">}</span></code> 参数到规则，来指定每个合并 Batch 的大小数量，这里也就是每两个 C++ 文件自动合并编译。</p>

<p>编译效果大概如下：</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> -r
</span>[ 11%]: ccache compiling.release build/.gens/test/unity_build/unity_642A245F.cpp
[ 11%]: ccache compiling.release build/.gens/test/unity_build/unity_bar.cpp
[ 11%]: ccache compiling.release build/.gens/test/unity_build/unity_73161A20.cpp
[ 11%]: ccache compiling.release build/.gens/test/unity_build/unity_F905F036.cpp
[ 11%]: ccache compiling.release build/.gens/test/unity_build/unity_foo.cpp
[ 11%]: ccache compiling.release build/.gens/test/unity_build/main.c
[ 77%]: linking.release test
[100%]: build ok
</code></pre>
</div>

<p>由于我们仅仅启用了 C++ 的 Unity Build，所以 C 代码还是正常挨个编译。另外在 Unity Build 模式下，我们还是可以做到尽可能的并行编译加速，互不冲突。</p>

<p>如果没有设置 <code class="highlighter-rouge">batchsize</code> 参数，那么默认会吧所有文件合并到一个文件中进行编译。</p>

<h4 id="group-模式">Group 模式</h4>

<p>如果上面的 Batch 模式自动合并效果不理想，我们也可以使用自定义分组，来手动配置哪些文件合并到一起参与编译，这使得用户更加地灵活可控。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"c++.unity_build"</span><span class="p">,</span> <span class="p">{</span><span class="n">batchsize</span> <span class="o">=</span> <span class="mi">0</span><span class="p">})</span> <span class="c1">-- disable batch mode</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"src/*.cpp"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/foo/*.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">unity_group</span> <span class="o">=</span> <span class="s2">"foo"</span><span class="p">})</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/bar/*.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">unity_group</span> <span class="o">=</span> <span class="s2">"bar"</span><span class="p">})</span>
</code></pre>
</div>

<p>我们使用 <code class="highlighter-rouge"><span class="p">{</span><span class="err">unity_group</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="nt">"foo"</span><span class="err">}</span></code> 来指定每个分组的名字，以及包含了哪些文件，每个分组的文件都会单独被合并到一个代码文件中去。</p>

<p>另外，<code class="highlighter-rouge">batchsize = 0</code> 也强行禁用了 Batch 模式，也就是说，没有设置 unity_group 分组的代码文件，我们还是会单独编译它们，也不会自动开启自动合并。</p>

<h4 id="batch-和-group-混合模式">Batch 和 Group 混合模式</h4>

<p>我们只要把上面的 <code class="highlighter-rouge">batchsize = 0</code> 改成非 0 值，就可以让分组模式下，剩余的代码文件继续开启 Batch 模式自动合并编译。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"src"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"c++.unity_build"</span><span class="p">,</span> <span class="p">{</span><span class="n">batchsize</span> <span class="o">=</span> <span class="mi">2</span><span class="p">})</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"src/*.cpp"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/foo/*.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">unity_group</span> <span class="o">=</span> <span class="s2">"foo"</span><span class="p">})</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/bar/*.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">unity_group</span> <span class="o">=</span> <span class="s2">"bar"</span><span class="p">})</span>
</code></pre>
</div>

<h4 id="忽略指定文件">忽略指定文件</h4>

<p>如果是 Batch 模式下，由于是自动合并操作，所以默认会对所有文件执行合并，但如果有些代码文件我们不想让它参与合并，那么我们也可以通过 <code class="highlighter-rouge"><span class="p">{</span><span class="err">unity_ignored</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="err">true</span><span class="p">}</span></code> 去忽略它们。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"src"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"c++.unity_build"</span><span class="p">,</span> <span class="p">{</span><span class="n">batchsize</span> <span class="o">=</span> <span class="mi">2</span><span class="p">})</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"src/*.cpp"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/test/*.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">unity_ignored</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span> <span class="c1">-- ignore these files</span>
</code></pre>
</div>

<h4 id="unique-id">Unique ID</h4>

<p>尽管 Unity Build 带啦的收益不错，但是我们还是会遇到一些意外的情况，比如我们的两个代码文件里面，全局命名空间下，都存在相同名字的全局变量和函数。</p>

<p>那么，合并编译就会带来编译冲突问题，编译器通常会报全局变量重定义错误。</p>

<p>为了解决这个问题，我们需要用户代码上做一些修改，然后配合构建工具来解决。</p>

<p>比如，我们的 foo.cpp 和 bar.cpp 都有全局变量 i。</p>

<p>foo.cpp</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="n">namespace</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">42</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">foo</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">return</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
</code></pre>
</div>

<p>bar.cpp</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="n">namespace</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">42</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">bar</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">return</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
</code></pre>
</div>

<p>那么，我们合并编译就会冲突，我们可以引入一个 Unique ID 来隔离全局的匿名空间。</p>

<p>foo.cpp</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="n">namespace</span> <span class="n">MY_UNITY_ID</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">42</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">foo</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">return</span> <span class="n">MY_UNITY_ID</span><span class="o">::</span><span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
</code></pre>
</div>

<p>bar.cpp</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="n">namespace</span> <span class="n">MY_UNITY_ID</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">42</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="n">bar</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">return</span> <span class="n">MY_UNITY_ID</span><span class="o">::</span><span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
</code></pre>
</div>

<p>接下来，我们还需要保证代码合并后， <code class="highlighter-rouge">MY_UNITY_ID</code> 在 foo 和 bar 中的定义完全不同，可以按文件名算一个唯一 ID 值出来，互不冲突，也就是实现下面的合并效果：</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cp">#define MY_UNITY_ID &lt;hash(foo.cpp)&gt;
#include "foo.c"
#undef MY_UNITY_ID
#define MY_UNITY_ID &lt;hash(bar.cpp)&gt;
#include "bar.c"
#undef MY_UNITY_ID
</span></code></pre>
</div>

<p>这看上去似乎很麻烦，但是用户不需要关心这些，xmake 会在合并时候自动处理它们，用户只需要指定这个 Unique ID 的名字就行了，例如下面这样：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"src"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"c++.unity_build"</span><span class="p">,</span> <span class="p">{</span><span class="n">batchsize</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">uniqueid</span> <span class="o">=</span> <span class="s2">"MY_UNITY_ID"</span><span class="p">})</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"src/*.cpp"</span><span class="p">)</span>
</code></pre>
</div>

<p>处理全局变量，还有全局的重名宏定义，函数什么的，都可以采用这种方式来避免冲突。</p>

<h3 id="c20-modules">C++20 Modules</h3>

<p>xmake 采用 <code class="highlighter-rouge">.mpp</code> 作为默认的模块扩展名，但是也同时支持 <code class="highlighter-rouge">.ixx</code>, <code class="highlighter-rouge">.cppm</code>, <code class="highlighter-rouge">.mxx</code> 等扩展名。</p>

<p>早期，xmake 试验性支持过 C++ Modules TS，但是那个时候，gcc 还不能很好的支持，并且模块间的依赖也不支持。</p>

<p>最近，我们对 xmake 做了大量改进，已经完整支持 gcc-11/clang/msvc 的 C++20 Modules 构建支持，并且能够自动分析模块间的依赖关系，实现最大化并行编译。</p>

<p>同时，对新版本的 clang/msvc 也做了更好地处理。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">set_languages</span><span class="p">(</span><span class="s2">"c++20"</span><span class="p">)</span>
<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cpp"</span><span class="p">,</span> <span class="s2">"src/*.mpp"</span><span class="p">)</span>
</code></pre>
</div>

<p>更多例子见：<a href="https://github.com/xmake-io/xmake/tree/master/tests/projects/c%2B%2B/modules">C++ Modules</a></p>

<h3 id="lua54-运行时支持">Lua5.4 运行时支持</h3>

<p>上个版本，我们增加了对 Lua5.3 运行时支持，而在这个版本中，我们进一步升级 Lua 运行时到 5.4，相比 5.3，运行性能和内存利用率上都有很大的提升。</p>

<p>不过，目前 xmake 的默认运行时还是 luajit，预计 2.6.1 版本（也就是下个版本），会正式切到 Lua5.4 作为默认的运行时。</p>

<p>尽管切换了 Lua 运行时，但是对于用户端，完全是无感知的，并且完全兼容现有工程配置，因为 xmake 原本就对暴露的 api 提供了一层封装，
对于 lua 版本之间存在兼容性问题的接口，例如 setfenv, ffi 等都隐藏在内部，原本就没有暴露给用户使用。</p>

<h3 id="keil-mdk-工具链支持">Keil MDK 工具链支持</h3>

<p>我们在这个版本中，还新增了 Keil/MDK 嵌入式编译工具链的支持，相关例子工程：<a href="https://github.com/xmake-io/xmake/tree/dev/tests/projects/mdk/hello">Example</a></p>

<p>xmake 会自动探测 Keil/MDK 安装的编译器，相关 issues <a href="https://github.com/xmake-io/xmake/issues/1753">#1753</a>。</p>

<h4 id="使用-armcc-编译">使用 armcc 编译</h4>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> f -p cross -a cortex-m3 --toolchain=armcc -c
</span><span class="w">$ </span><span class="nc">xmake</span><span class="kv">
</span></code></pre>
</div>

<h4 id="使用-armclang-编译">使用 armclang 编译</h4>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> f -p cross -a cortex-m3 --toolchain=armclang -c
</span><span class="w">$ </span><span class="nc">xmake</span><span class="kv">
</span></code></pre>
</div>

<h4 id="控制台程序-1">控制台程序</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>
    <span class="n">add_deps</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"mdk.console"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"src/*.s"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"__EVAL"</span><span class="p">,</span> <span class="s2">"__MICROLIB"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"src/lib/cmsis"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="静态库程序-1">静态库程序</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.debug"</span><span class="p">,</span> <span class="s2">"mode.release"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"mdk.static"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/foo/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="wasi-工具链支持">Wasi 工具链支持</h3>

<p>之前我们支持了 wasm 平台的 emcc 工具链来构建 wasm 程序，而这里，我们新加了另外一个启用了 WASI 的 Wasm 工具链来替换 emcc。</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> f -p wasm --toolchain=wasi
</span><span class="w">$ </span><span class="nc">xmake</span><span class="kv">
</span></code></pre>
</div>

<h3 id="circle-工具链支持">Circle 工具链支持</h3>

<p>我们还新增了 circle 编译器的支持，这是个新的 C++20 编译器，额外附带了一些有趣的编译期元编程特性，有兴趣的同学可以到官网查看：https://www.circle-lang.org/</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> f --toolchain=circle
</span><span class="w">$ </span><span class="nc">xmake</span><span class="kv">
</span></code></pre>
</div>

<h3 id="gcc-891011-特定版本支持">gcc-8/9/10/11 特定版本支持</h3>

<p>如果用户额外安装了 gcc-11, gcc-10 等特定版本的 gcc 工具链，在本地的 gcc 程序命名可能是 <code class="highlighter-rouge">/usr/bin/gcc-11</code>。</p>

<p>一种办法是通过 <code class="highlighter-rouge">xmake f --cc=gcc-11 --cxx=gcc-11 --ld=g++-11</code> 挨个指定配置来切换，但非常繁琐。</p>

<p>所以，xmake 也提供了更加快捷的切换方式：</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> f --toolchain=gcc-11 -c
</span><span class="w">$ </span><span class="nc">xmake</span><span class="kv">
</span></code></pre>
</div>

<p>只需要指定 <code class="highlighter-rouge">gcc-11</code> 对应的版本名，就可以快速切换整个 gcc 工具链。</p>

<h3 id="c1720-编译器特性检测">C++17/20 编译器特性检测</h3>

<p>xmake 提供了 check_features 辅助接口来检测编译器特性。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">includes</span><span class="p">(</span><span class="s2">"check_features.lua"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"*.c"</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"config.h.in"</span><span class="p">)</span>
    <span class="n">configvar_check_features</span><span class="p">(</span><span class="s2">"HAS_CONSTEXPR"</span><span class="p">,</span> <span class="s2">"cxx_constexpr"</span><span class="p">)</span>
    <span class="n">configvar_check_features</span><span class="p">(</span><span class="s2">"HAS_CONSEXPR_AND_STATIC_ASSERT"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"cxx_constexpr"</span><span class="p">,</span> <span class="s2">"c_static_assert"</span><span class="p">},</span> <span class="p">{</span><span class="n">languages</span> <span class="o">=</span> <span class="s2">"c++11"</span><span class="p">})</span>
</code></pre>
</div>

<p>config.h.in</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_CONSTEXPR</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_CONSEXPR_AND_STATIC_ASSERT</span><span class="p">}</span>
</code></pre>
</div>

<p>config.h</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cm">/* #undef HAS_CONSTEXPR */</span>
<span class="cp">#define HAS_CONSEXPR_AND_STATIC_ASSERT 1
</span></code></pre>
</div>

<p>而在 2.5.9 版本中，我们新增了 c++17 特性检测：</p>

<table>
  <thead>
    <tr>
      <th>特性名</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>cxx_aggregate_bases</td>
    </tr>
    <tr>
      <td>cxx_aligned_new</td>
    </tr>
    <tr>
      <td>cxx_capture_star_this</td>
    </tr>
    <tr>
      <td>cxx_constexpr</td>
    </tr>
    <tr>
      <td>cxx_deduction_guides</td>
    </tr>
    <tr>
      <td>cxx_enumerator_attributes</td>
    </tr>
    <tr>
      <td>cxx_fold_expressions</td>
    </tr>
    <tr>
      <td>cxx_guaranteed_copy_elision</td>
    </tr>
    <tr>
      <td>cxx_hex_float</td>
    </tr>
    <tr>
      <td>cxx_if_constexpr</td>
    </tr>
    <tr>
      <td>cxx_inheriting_constructors</td>
    </tr>
    <tr>
      <td>cxx_inline_variables</td>
    </tr>
    <tr>
      <td>cxx_namespace_attributes</td>
    </tr>
    <tr>
      <td>cxx_noexcept_function_type</td>
    </tr>
    <tr>
      <td>cxx_nontype_template_args</td>
    </tr>
    <tr>
      <td>cxx_nontype_template_parameter_auto</td>
    </tr>
    <tr>
      <td>cxx_range_based_for</td>
    </tr>
    <tr>
      <td>cxx_static_assert</td>
    </tr>
    <tr>
      <td>cxx_structured_bindings</td>
    </tr>
    <tr>
      <td>cxx_template_template_args</td>
    </tr>
    <tr>
      <td>cxx_variadic_using</td>
    </tr>
  </tbody>
</table>

<p>还新增了 c++20 特性检测：</p>

<table>
  <thead>
    <tr>
      <th>特性名</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>cxx_aggregate_paren_init</td>
    </tr>
    <tr>
      <td>cxx_char8_t</td>
    </tr>
    <tr>
      <td>cxx_concepts</td>
    </tr>
    <tr>
      <td>cxx_conditional_explicit</td>
    </tr>
    <tr>
      <td>cxx_consteval</td>
    </tr>
    <tr>
      <td>cxx_constexpr</td>
    </tr>
    <tr>
      <td>cxx_constexpr_dynamic_alloc</td>
    </tr>
    <tr>
      <td>cxx_constexpr_in_decltype</td>
    </tr>
    <tr>
      <td>cxx_constinit</td>
    </tr>
    <tr>
      <td>cxx_deduction_guides</td>
    </tr>
    <tr>
      <td>cxx_designated_initializers</td>
    </tr>
    <tr>
      <td>cxx_generic_lambdas</td>
    </tr>
    <tr>
      <td>cxx_impl_coroutine</td>
    </tr>
    <tr>
      <td>cxx_impl_destroying_delete</td>
    </tr>
    <tr>
      <td>cxx_impl_three_way_comparison</td>
    </tr>
    <tr>
      <td>cxx_init_captures</td>
    </tr>
    <tr>
      <td>cxx_modules</td>
    </tr>
    <tr>
      <td>cxx_nontype_template_args</td>
    </tr>
    <tr>
      <td>cxx_using_enum</td>
    </tr>
  </tbody>
</table>

<h3 id="xrepo-包虚拟环境管理">Xrepo 包虚拟环境管理</h3>

<h4 id="进入虚拟环境">进入虚拟环境</h4>

<p>xmake 自带的 xrepo 包管理工具，现在已经可以很好的支持包虚拟机环境管理，类似 nixos 的 nixpkgs。</p>

<p>我们可以通过在当前目录下，添加 xmake.lua 文件，定制化一些包配置，然后进入特定的包虚拟环境。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"zlib 1.2.11"</span><span class="p">)</span>
<span class="n">add_requires</span><span class="p">(</span><span class="s2">"python 3.x"</span><span class="p">,</span> <span class="s2">"luajit"</span><span class="p">)</span>
</code></pre>
</div>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xrepo</span><span class="kv"> env shell
</span>&gt; python --version
&gt; luajit --version
</code></pre>
</div>

<p>我们也可以在 xmake.lua 配置加载对应的工具链环境，比如加载 vs 的编译环境。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">set_toolchains</span><span class="p">(</span><span class="s2">"msvc"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="管理虚拟环境">管理虚拟环境</h4>

<p>我们可以使用下面的命令，把指定的虚拟环境配置全局注册到系统中，方便快速切换。</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xrepo</span><span class="kv"> env --add /tmp/base.lua
</span></code></pre>
</div>

<p>这个时候，我们就保存了一个名叫 base 的全局虚拟环境，我们可以通过 list 命令去查看它。</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xrepo</span><span class="kv"> env --list
</span>/Users/ruki/.xmake/envs:
  - base
envs(1) found!
</code></pre>
</div>

<p>我们也可以删除它。</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xrepo</span><span class="kv"> env --remove base
</span></code></pre>
</div>

<h4 id="切换全局虚拟环境">切换全局虚拟环境</h4>

<p>如果我们注册了多个虚拟环境，我们也可以快速切换它们。</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xrepo</span><span class="kv"> env -b base shell
</span>&gt; python --version
</code></pre>
</div>

<p>或者直接加载指定虚拟环境运行特定命令</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xrepo</span><span class="kv"> env -b base python --version
</span></code></pre>
</div>

<p><code class="highlighter-rouge">xrepo env -b/--bind</code> 就是绑定指定的虚拟环境，更多详情见：<a href="https://github.com/xmake-io/xmake/issues/1762">#1762</a></p>

<h3 id="header-only-目标类型">Header Only 目标类型</h3>

<p>对于 target，我们新增了 <code class="highlighter-rouge">headeronly</code> 目标类型，这个类型的目标程序，我们不会实际编译它们，因为它没有源文件需要被编译。</p>

<p>但是它包含了头文件列表，这通常用于 headeronly 库项目的安装，IDE 工程的文件列表生成，以及安装阶段的 cmake/pkgconfig 导入文件的生成。</p>

<p>例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.release"</span><span class="p">,</span> <span class="s2">"mode.debug"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"headeronly"</span><span class="p">)</span>
    <span class="n">add_headerfiles</span><span class="p">(</span><span class="s2">"src/foo.h"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"utils.install.cmake_importfiles"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"utils.install.pkgconfig_importfiles"</span><span class="p">)</span>
</code></pre>
</div>

<p>更多详情见：<a href="https://github.com/xmake-io/xmake/issues/1747">#1747</a></p>

<h3 id="从-cmake-中查找包">从 CMake 中查找包</h3>

<p>现在 cmake 已经是事实上的标准，所以 CMake 提供的 find_package 已经可以查找大量的库和模块，我们完全复用 cmake 的这部分生态来扩充 xmake 对包的集成。</p>

<p>我们可以通过 <code class="highlighter-rouge">find_package("cmake::xxx")</code> 去借助 cmake 来找一些包，xmake 会自动生成一个 cmake 脚本来调用 cmake 的 find_package 去查找一些包，获取里面包信息。</p>

<p>例如：</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> l find_package cmake::ZLIB
</span>{
  links = {
    "z"
  },
  includedirs = {
    "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.
15.sdk/usr/include"
  },
  linkdirs = {
    "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.
15.sdk/usr/lib"
  }
}
<span class="w">$ </span><span class="nc">xmake</span><span class="kv"> l find_package cmake::LibXml2
</span>{
  links = {
    "xml2"
  },
  includedirs = {
    "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/libxml2"
  },
  linkdirs = {
    "/usr/lib"
  }
}
</code></pre>
</div>

<h4 id="指定版本">指定版本</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">find_package</span><span class="p">(</span><span class="s2">"cmake::OpenCV"</span><span class="p">,</span> <span class="p">{</span><span class="n">required_version</span> <span class="o">=</span> <span class="s2">"4.1.1"</span><span class="p">})</span>
</code></pre>
</div>

<h4 id="指定组件">指定组件</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">find_package</span><span class="p">(</span><span class="s2">"cmake::Boost"</span><span class="p">,</span> <span class="p">{</span><span class="n">components</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"regex"</span><span class="p">,</span> <span class="s2">"system"</span><span class="p">}})</span>
</code></pre>
</div>

<h4 id="预设开关">预设开关</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">find_package</span><span class="p">(</span><span class="s2">"cmake::Boost"</span><span class="p">,</span> <span class="p">{</span><span class="n">components</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"regex"</span><span class="p">,</span> <span class="s2">"system"</span><span class="p">},</span> <span class="n">presets</span> <span class="o">=</span> <span class="p">{</span><span class="n">Boost_USE_STATIC_LIB</span> <span class="o">=</span> <span class="kc">true</span><span class="p">}})</span>
<span class="n">set</span><span class="p">(</span><span class="n">Boost_USE_STATIC_LIB</span> <span class="n">ON</span><span class="p">)</span> <span class="c1">-- will be used in FindBoost.cmake</span>
<span class="n">find_package</span><span class="p">(</span><span class="n">Boost</span> <span class="n">REQUIRED</span> <span class="n">COMPONENTS</span> <span class="n">regex</span> <span class="n">system</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="设置环境变量">设置环境变量</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">find_package</span><span class="p">(</span><span class="s2">"cmake::OpenCV"</span><span class="p">,</span> <span class="p">{</span><span class="n">envs</span> <span class="o">=</span> <span class="p">{</span><span class="n">CMAKE_PREFIX_PATH</span> <span class="o">=</span> <span class="s2">"xxx"</span><span class="p">}})</span>
</code></pre>
</div>

<h4 id="指定自定义-findfoocmake-模块脚本目录">指定自定义 FindFoo.cmake 模块脚本目录</h4>

<p>mydir/cmake_modules/FindFoo.cmake</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">find_package</span><span class="p">(</span><span class="s2">"cmake::Foo"</span><span class="p">,</span> <span class="p">{</span><span class="n">moduledirs</span> <span class="o">=</span> <span class="s2">"mydir/cmake_modules"</span><span class="p">})</span>
</code></pre>
</div>

<h4 id="包依赖集成">包依赖集成</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">package</span><span class="p">(</span><span class="s2">"xxx"</span><span class="p">)</span>
    <span class="n">on_fetch</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="n">opt</span><span class="p">)</span>
         <span class="k">return</span> <span class="n">package</span><span class="p">:</span><span class="n">find_package</span><span class="p">(</span><span class="s2">"cmake::xxx"</span><span class="p">,</span> <span class="n">opt</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
<span class="n">package_end</span><span class="p">()</span>

<span class="n">add_requires</span><span class="p">(</span><span class="s2">"xxx"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="包依赖集成可选组件">包依赖集成（可选组件）</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">package</span><span class="p">(</span><span class="s2">"boost"</span><span class="p">)</span>
    <span class="n">add_configs</span><span class="p">(</span><span class="s2">"regex"</span><span class="p">,</span>   <span class="p">{</span> <span class="n">description</span> <span class="o">=</span> <span class="s2">"Enable regex."</span><span class="p">,</span> <span class="n">default</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="s2">"boolean"</span><span class="p">})</span>
    <span class="n">on_fetch</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="n">opt</span><span class="p">)</span>
         <span class="n">opt</span><span class="p">.</span><span class="n">components</span> <span class="o">=</span> <span class="p">{}</span>
         <span class="k">if</span> <span class="n">package</span><span class="p">:</span><span class="n">config</span><span class="p">(</span><span class="s2">"regex"</span><span class="p">)</span> <span class="k">then</span>
             <span class="nb">table.insert</span><span class="p">(</span><span class="n">opt</span><span class="p">.</span><span class="n">components</span><span class="p">,</span> <span class="s2">"regex"</span><span class="p">)</span>
         <span class="k">end</span>
         <span class="k">return</span> <span class="n">package</span><span class="p">:</span><span class="n">find_package</span><span class="p">(</span><span class="s2">"cmake::Boost"</span><span class="p">,</span> <span class="n">opt</span><span class="p">)</span>
    <span class="k">end</span><span class="p">)</span>
<span class="n">package_end</span><span class="p">()</span>

<span class="n">add_requires</span><span class="p">(</span><span class="s2">"boost"</span><span class="p">,</span> <span class="p">{</span><span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">regex</span> <span class="o">=</span> <span class="kc">true</span><span class="p">}})</span>
</code></pre>
</div>

<p>相关 issues: <a href="https://github.com/xmake-io/xmake/issues/1632">#1632</a></p>

<h3 id="添加自定义命令到-cmakeliststxt">添加自定义命令到 CMakelists.txt</h3>

<p>我们进一步改进了 cmake 生成器，现在可以将 rule 里面自定义的脚本序列化成命令列表，一起生成到 CMakelists.txt</p>

<p>不过目前只能支持 batchcmds 系列脚本的序列化。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">rule</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">after_buildcmd</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">batchcmds</span><span class="p">,</span> <span class="n">opt</span><span class="p">)</span>
        <span class="n">batchcmds</span><span class="p">:</span><span class="n">show</span><span class="p">(</span><span class="s2">"hello xmake!"</span><span class="p">)</span>
        <span class="n">batchcmds</span><span class="p">:</span><span class="n">cp</span><span class="p">(</span><span class="s2">"xmake.lua"</span><span class="p">,</span> <span class="s2">"/tmp/"</span><span class="p">)</span>
        <span class="c1">-- batchcmds:execv("echo", {"hello", "world!"})</span>
        <span class="c1">-- batchcmds:runv("echo", {"hello", "world!"})</span>
    <span class="k">end</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_rules</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>它将会生成类似如下的 CMakelists.txt</p>

<div class="highlighter-rouge"><pre class="highlight"><code># ...
add_custom_command(TARGET test
    POST_BUILD
    COMMAND echo hello xmake!
    VERBATIM
)
add_custom_command(TARGET test
    POST_BUILD
    COMMAND cp xmake.lua /tmp/
    VERBATIM
)
target_sources(test PRIVATE
    src/main.c
)
</code></pre>
</div>

<p>不过 cmake 的 <code class="highlighter-rouge">ADD_CUSTOM_COMMAND</code> PRE_BUILD 实际效果在不同生成器上，差异比较大，无法满足我们的需求，因此我们做了很多处理来支持它。</p>

<p>相关 issues: <a href="https://github.com/xmake-io/xmake/issues/1735">#1735</a></p>

<h3 id="改进对-nixos-的安装支持">改进对 NixOS 的安装支持</h3>

<p>我们还改进了 get.sh 安装脚本，来更好地支持 nixOS。</p>

<h2 id="更新内容">更新内容</h2>

<h3 id="新特性">新特性</h3>

<ul>
  <li><a href="https://github.com/xmake-io/xmake/issues/1736">#1736</a>: 支持 wasi-sdk 工具链</li>
  <li>支持 Lua 5.4 运行时</li>
  <li>添加 gcc-8, gcc-9, gcc-10, gcc-11 工具链</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1632">#1623</a>: 支持 find_package 从 cmake 查找包</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1747">#1747</a>: 添加 <code class="highlighter-rouge">set_kind("headeronly")</code> 更好的处理 headeronly 库的安装</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1019">#1019</a>: 支持 Unity build</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1438">#1438</a>: 增加 <code class="highlighter-rouge">xmake l cli.amalgamate</code> 命令支持代码合并</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1756">#1765</a>: 支持 nim 语言</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1762">#1762</a>: 为 <code class="highlighter-rouge">xrepo env</code> 管理和切换指定的环境配置</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1767">#1767</a>: 支持 Circle 编译器</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1753">#1753</a>: 支持 Keil/MDK 的 armcc/armclang 工具链</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1774">#1774</a>: 添加 table.contains api</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1735">#1735</a>: 添加自定义命令到 cmake 生成器</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1781">#1781</a>: 改进 get.sh 安装脚本支持 nixos</li>
</ul>

<h3 id="改进">改进</h3>

<ul>
  <li><a href="https://github.com/xmake-io/xmake/issues/1528">#1528</a>: 检测 c++17/20 特性</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1729">#1729</a>: 改进 C++20 modules 对 clang/gcc/msvc 的支持，支持模块间依赖编译和并行优化</li>
  <li><a href="https://github.com/xmake-io/xmake/issues/1779">#1779</a>: 改进 ml.exe/x86，移除内置的 <code class="highlighter-rouge">-Gd</code> 选项</li>
</ul>


        </article>
        <hr>

        <!-- baidu ads -->
        

        <!-- reward -->
        <div style="text-align: center;">
            <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
              <span>赏</span>
            </button>
            <div id="QR" style="display: none;">
                <div id="wechat" style="display: inline-block">
                  <img id="wechat_qr" src="/static/img/weixin.png" alt="WeChat Pay"/>
                  <p>微信打赏</p>
                </div>
                <div id="alipay" style="display: inline-block">
                  <img id="alipay_qr" src="/static/img/alipay.png" alt="Alipay"/>
                  <p>支付宝打赏</p>
                </div>
            </div>
        </div>

        
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
                    
                    <h2 id="english">English</h2>
                    <ul>
                    
                    <li class="relatedPost">
                        <a href="/2021/10/30/xmake-update-v2.5.9/">xmake v2.5.9 released, Improve C++20 Modules and support Nim, Keil MDK and Unity Build
                        
                        </a>
                    </li>
                    
                    
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
        
            </ul>
        

        
        
            
        
            
            
            
                
                    
                        
                        <h2 id="similar_posts">相关文章</h2>
                        <ul>
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/17/xmake-update-v2.6.2/">xmake v2.6.2 发布，新增 Linux 内核驱动模块构建支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 发布，使用 Lua5.4 运行时，Rust 和 C++ 混合编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 发布，新增 Pascal/Swig 程序和 Lua53 运行时支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/08/29/xmake-update-v2.5.7/">xmake v2.5.7 发布，包依赖锁定和 Vala/Metal 语言编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
        
            </ul>
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        

        

        

        
        
        <p><strong>上一篇</strong> <a href="/cn/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 发布，新增 Pascal/Swig 程序和 Lua53 运行时支持</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        

        

        

        
        
        <p><strong>下一篇</strong> <a href="/cn/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 发布，使用 Lua5.4 运行时，Rust 和 C++ 混合编译支持</a></p>
        
    </div>
</div>


        <h2 id="comments">评论</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,       
  language: 'zh-CN',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">

            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    内容
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#english">English</a></li>
                    <li><a href="#similar_posts">相关文章</a></li>
                    <li><a href="#comments">评论</a></li>
                </ul>
            </div>


            <!-- baidu ads -->
            
            
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    链接
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- xmake courses -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    xmake 入门课程
                </div>
                <a href="https://xmake.io/#/zh-cn/about/course" target="_blank">
                <img src="/static/img/xmake-course.png" alt="course" width="256" height="193">
                </a>
            </div>

            <!-- qqgroup -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    技术交流群（QQ）
                </div>
                <img src="/static/img/qqgroup.png" alt="qqgroup" width="256" height="284">
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
